const SerialPort = require('serialport')

const readlineSync = require('readline-sync')
let com = readlineSync.question("Input ur serialPort:")

const port = new SerialPort(com)
let comData
port.on('error', function (err) {
  console.log('Error: ', err.message)
})
process.on('SIGINT', function () {
  console.log('Exit now!');
  process.exit();
});
// while (true) {
port.on('data', function (data) {
  console.log('数据接收: ' ,data);
  data += ""
  for (let i = 0; i < data.length; i++) {
    setTimeout(() => {
      port.write(data.charAt(i), function (err) {
        if (err) {
          return console.log('Error on write: ', err.message)
        }
      })
    }, 300*(i+1));
  }
});
// }